package com.handsome.适配器模式.spring源码;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author niechun
 * @date 2023/2/2 22:12
 */
public class DispatcherServlet {

    public static List<HandleAdapter> HandleAdapters= new ArrayList<>(Arrays.asList(new SimpleControllerHandleAdapter(),new SimpleServletHandleAdapter()));

    public static void doDispatcher(Controller controller) throws Exception{
        HandleAdapter adapter = getAdapter(controller);
        adapter.handle(controller);
    }

    private static HandleAdapter getAdapter(Controller controller)  throws Exception{
        for (HandleAdapter handleAdapter : HandleAdapters) {
            if (handleAdapter.supports(controller)){
                return handleAdapter;
            }
        }
      throw new Exception();
    }

    public static void main(String[] args) throws Exception {
        doDispatcher(new SimpleController());
    }
}
